﻿using Sasa.QualityTools.CodeAnalysis.Core.Models;
using System;

namespace Sasa.QualityTools.CodeAnalysis.FxCopIntegrator.ViewModels
{
    public class RuleViewModel : ViewModelBase
    {
        private Rule rule;

        private bool hasUrl;


        public string CheckId
        {
            get
            {
                return rule.CheckId;
            }
            set
            {
                rule.CheckId = value;
                OnPropertyChanged("CheckId");
            }
        }

        public string Category
        {
            get
            {
                return rule.Category;
            }
            set
            {
                rule.Category = value;
                OnPropertyChanged("Category");
            }
        }

        public string TypeName
        {
            get
            {
                return rule.TypeName;
            }
            set
            {
                rule.TypeName = value;
                OnPropertyChanged("TypeName");
            }
        }


        public string Name
        {
            get
            {
                return rule.Name;
            }
            set
            {
                rule.Name = value;
                OnPropertyChanged("Name");
            }
        }

        public string Description
        {
            get
            {
                return rule.Description;
            }
            set
            {
                rule.Description = value;
                OnPropertyChanged("Description");
            }
        }

        public string Url
        {
            get
            {
                return rule.Url;
            }
            set
            {
                HasUrl = Uri.IsWellFormedUriString(value, UriKind.Absolute);
                rule.Url = value;
                OnPropertyChanged("Url");
            }
        }

        public bool HasUrl
        {
            get
            {
                return hasUrl;
            }
            private set
            {
                hasUrl = value;
                OnPropertyChanged("HasUrl");
            }
        }


        public RuleViewModel()
            : this(new Rule())
        {
        }

        public RuleViewModel(Rule rule)
        {
            this.rule = rule;
            HasUrl = Uri.IsWellFormedUriString(rule.Url, UriKind.Absolute);
        }
    }
}
